home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / BeOS / WAVE.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-02-03  |  14.9 KB  |  641 lines

  1. /* generic.c */
  2.  
  3. /* Demo of BEOS Mesa rendering */
  4.  
  5. /*
  6.  * See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions.
  7.  *
  8.  * If you want to render BIG images you'll probably have to increase
  9.  * MAX_WIDTH and MAX_HEIGHT in src/config.h.
  10.  *
  11.  * This program is in the public domain.
  12.  *
  13.  * BEOS output provided by Tinic Urou
  14.  * 5uro@informatik.uni-hamburg.de
  15.  */
  16.  
  17. #include <AppKit.h>
  18. #include <InterfaceKit.h>
  19. #include <KernelKit.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <math.h>
  24. #include "GL/osmesa.h"
  25. #include "GL/glu.h"
  26.  
  27. #ifndef PI
  28. #define PI 3.14159265358979323846
  29. #endif
  30.  
  31. #define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)]))
  32. #define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX]))
  33.  
  34. GLenum rgb, doubleBuffer, directRender;
  35.  
  36. GLint colorIndexes1[3];
  37. GLint colorIndexes2[3];
  38. GLenum clearMask = (GLenum)(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  39.  
  40. GLenum smooth = GL_FALSE;
  41. GLenum lighting = GL_TRUE;
  42. GLenum depth = GL_TRUE;
  43. GLenum stepMode = GL_FALSE;
  44. GLenum spinMode = GL_FALSE;
  45. GLint contouring = 0;
  46.  
  47. GLint widthX, widthY;
  48. GLint checkerSize;
  49. float height;
  50.  
  51. GLint frames, curFrame = 0, nextFrame = 0;
  52.  
  53. struct facet {
  54.     float color[3];
  55.     float normal[3];
  56. };
  57. struct coord {
  58.     float vertex[3];
  59.     float normal[3];
  60. };
  61. struct mesh {
  62.     GLint widthX, widthY;
  63.     GLint numFacets;
  64.     GLint numCoords;
  65.     GLint frames;
  66.     struct coord *coords;
  67.     struct facet *facets;
  68. } theMesh;
  69.  
  70. GLubyte contourTexture1[] = {
  71.     255, 255, 255, 255,
  72.     255, 255, 255, 255,
  73.     255, 255, 255, 255,
  74.     127, 127, 127, 127,
  75. };
  76. GLubyte contourTexture2[] = {
  77.     255, 255, 255, 255,
  78.     255, 127, 127, 127,
  79.     255, 127, 127, 127,
  80.     255, 127, 127, 127,
  81. };
  82.  
  83.  
  84. static void Animate(void)
  85. {
  86.     struct coord *coord;
  87.     struct facet *facet;
  88.     float *lastColor;
  89.     float *thisColor;
  90.     GLint i, j;
  91.  
  92.     glClear(clearMask);
  93.  
  94.     if (nextFrame || !stepMode) {
  95.     curFrame++;
  96.     }
  97.     if (curFrame >= theMesh.frames) {
  98.     curFrame = 0;
  99.     }
  100.  
  101.     if ((nextFrame || !stepMode) && spinMode) {
  102.     glRotatef(5.0, 0.0, 0.0, 1.0);
  103.     }
  104.     nextFrame = 0;
  105.  
  106.     for (i = 0; i < theMesh.widthX; i++) {
  107.     glBegin(GL_QUAD_STRIP);
  108.     lastColor = NULL;
  109.     for (j = 0; j < theMesh.widthY; j++) {
  110.         facet = GETFACET(curFrame, i, j);
  111.         if (!smooth && lighting) {
  112.         glNormal3fv(facet->normal);
  113.         }
  114.         if (lighting) {
  115.         if (rgb) {
  116.             thisColor = facet->color;
  117.             glColor3fv(facet->color);
  118.         } else {
  119.             thisColor = facet->color;
  120.             glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, 
  121.                  facet->color);
  122.         }
  123.         } else {
  124.         if (rgb) {
  125.             thisColor = facet->color;
  126.             glColor3fv(facet->color);
  127.         } else {
  128.             thisColor = facet->color;
  129.             glIndexf(facet->color[1]);
  130.         }
  131.         }
  132.  
  133.         if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) {
  134.         if (lastColor) {
  135.             glEnd();
  136.             glBegin(GL_QUAD_STRIP);
  137.         }
  138.         coord = GETCOORD(curFrame, i, j);
  139.         if (smooth && lighting) {
  140.             glNormal3fv(coord->normal);
  141.         }
  142.         glVertex3fv(coord->vertex);
  143.  
  144.         coord = GETCOORD(curFrame, i+1, j);
  145.         if (smooth && lighting) {
  146.             glNormal3fv(coord->normal);
  147.         }
  148.         glVertex3fv(coord->vertex);
  149.         }
  150.  
  151.         coord = GETCOORD(curFrame, i, j+1);
  152.         if (smooth && lighting) {
  153.         glNormal3fv(coord->normal);
  154.         }
  155.         glVertex3fv(coord->vertex);
  156.  
  157.         coord = GETCOORD(curFrame, i+1, j+1);
  158.         if (smooth && lighting) {
  159.         glNormal3fv(coord->normal);
  160.         }
  161.         glVertex3fv(coord->vertex);
  162.  
  163.         lastColor = thisColor;
  164.     }
  165.     glEnd();
  166.     }
  167.  
  168.     glFlush();
  169. }
  170.  
  171. static void InitMesh(void)
  172. {
  173.     struct coord *coord;
  174.     struct facet *facet;
  175.     float dp1[3], dp2[3];
  176.     float *pt1, *pt2, *pt3;
  177.     float angle, d, x, y;
  178.     GLint numFacets, numCoords, frameNum, i, j;
  179.  
  180.     theMesh.widthX = widthX;
  181.     theMesh.widthY = widthY;
  182.     theMesh.frames = frames;
  183.  
  184.     numFacets = widthX * widthY;
  185.     numCoords = (widthX + 1) * (widthY + 1);
  186.  
  187.     theMesh.numCoords = numCoords;
  188.     theMesh.numFacets = numFacets;
  189.  
  190.     theMesh.coords = (struct coord *)malloc(frames*numCoords*
  191.                         sizeof(struct coord));
  192.     theMesh.facets = (struct facet *)malloc(frames*numFacets*
  193.                         sizeof(struct facet));
  194.  
  195.     for (frameNum = 0; frameNum < frames; frameNum++) {
  196.     for (i = 0; i <= widthX; i++) {
  197.         x = i / (float)widthX;
  198.         for (j = 0; j <= widthY; j++) {
  199.         y = j / (float)widthY;
  200.  
  201.         d = sqrt(x*x+y*y);
  202.         if (d == 0.0) {
  203.             d = 0.0001;
  204.         }
  205.         angle = 2 * PI * d + (2 * PI / frames * frameNum);
  206.  
  207.         coord = GETCOORD(frameNum, i, j);
  208.  
  209.         coord->vertex[0] = x - 0.5;
  210.         coord->vertex[1] = y - 0.5;
  211.         coord->vertex[2] = (height - height * d) * cos(angle);
  212.  
  213.         coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI *
  214.                    sin(angle) + cos(angle));
  215.         coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI *
  216.                    sin(angle) + cos(angle));
  217.         coord->normal[2] = -1;
  218.  
  219.         d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+
  220.                    coord->normal[1]*coord->normal[1]+1);
  221.         coord->normal[0] *= d;
  222.         coord->normal[1] *= d;
  223.         coord->normal[2] *= d;
  224.         }
  225.     }
  226.     for (i = 0; i < widthX; i++) {
  227.         for (j = 0; j < widthY; j++) {
  228.         facet = GETFACET(frameNum, i, j);
  229.         if (((i/checkerSize)%2)^(j/checkerSize)%2) {
  230.             if (rgb) {
  231.             facet->color[0] = 1.0;
  232.             facet->color[1] = 0.2;
  233.             facet->color[2] = 0.2;
  234.             } else {
  235.             facet->color[0] = colorIndexes1[0];
  236.             facet->color[1] = colorIndexes1[1];
  237.             facet->color[2] = colorIndexes1[2];
  238.             }
  239.         } else {
  240.             if (rgb) {
  241.             facet->color[0] = 0.2;
  242.             facet->color[1] = 1.0;
  243.             facet->color[2] = 0.2;
  244.             } else {
  245.             facet->color[0] = colorIndexes2[0];
  246.             facet->color[1] = colorIndexes2[1];
  247.             facet->color[2] = colorIndexes2[2];
  248.             }
  249.         }
  250.         pt1 = GETCOORD(frameNum, i, j)->vertex;
  251.         pt2 = GETCOORD(frameNum, i, j+1)->vertex;
  252.         pt3 = GETCOORD(frameNum, i+1, j+1)->vertex;
  253.  
  254.         dp1[0] = pt2[0] - pt1[0];
  255.         dp1[1] = pt2[1] - pt1[1];
  256.         dp1[2] = pt2[2] - pt1[2];
  257.  
  258.         dp2[0] = pt3[0] - pt2[0];
  259.         dp2[1] = pt3[1] - pt2[1];
  260.         dp2[2] = pt3[2] - pt2[2];
  261.  
  262.         facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1];
  263.         facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2];
  264.         facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0];
  265.  
  266.         d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+
  267.                    facet->normal[1]*facet->normal[1]+
  268.                    facet->normal[2]*facet->normal[2]);
  269.  
  270.         facet->normal[0] *= d;
  271.         facet->normal[1] *= d;
  272.         facet->normal[2] *= d;
  273.         }
  274.     }
  275.     }
  276. }
  277.  
  278. static void InitMaterials(void)
  279. {
  280.     static float ambient[] = {0.1, 0.1, 0.1, 1.0};
  281.     static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
  282.     static float position[] = {90.0, 90.0, 150.0, 0.0};
  283.     static float front_mat_shininess[] = {60.0};
  284.     static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
  285.     static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
  286.     static float back_mat_shininess[] = {60.0};
  287.     static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
  288.     static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
  289.     static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
  290.     static float lmodel_twoside[] = {GL_TRUE};
  291.  
  292.     glMatrixMode(GL_PROJECTION);
  293.     gluPerspective(90.0, 1.0, 0.5, 10.0);
  294.  
  295.     glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  296.     glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  297.     glLightfv(GL_LIGHT0, GL_POSITION, position);
  298.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  299.     glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  300.     glEnable(GL_LIGHTING);
  301.     glEnable(GL_LIGHT0);
  302.     
  303.     glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
  304.     glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
  305.     glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  306.     glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
  307.     glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
  308.     glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
  309.  
  310.     glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  311.     glEnable(GL_COLOR_MATERIAL);
  312. }
  313.  
  314. static void InitTexture(void)
  315. {
  316.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  317.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  318.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  319.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  320.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  321. }
  322.  
  323. static void Init(void)
  324. {
  325.     glClearColor(0.0, 0.0, 0.0, 0.0);
  326.     glShadeModel(GL_FLAT);
  327.     glFrontFace(GL_CW);
  328.     glEnable(GL_DEPTH_TEST);
  329.  
  330.     InitMaterials();
  331.     InitTexture();
  332.     InitMesh();
  333.  
  334.     glMatrixMode(GL_MODELVIEW);
  335.     glTranslatef(0.0, 0.4, -1.8);
  336.     glScalef(2.0, 2.0, 2.0);
  337.     glRotatef(-35.0, 1.0, 0.0, 0.0);
  338.     glRotatef(35.0, 0.0, 0.0, 1.0);
  339. }
  340.  
  341. static void Reshape(int width, int height)
  342. {
  343.     glViewport(0, 0, (GLint)width, (GLint)height);
  344. }
  345.  
  346. static GLenum Args(int argc, char **argv)
  347. {
  348.     GLint i;
  349.  
  350.     rgb = GL_TRUE;
  351.     doubleBuffer = GL_FALSE;
  352.     directRender = GL_TRUE;
  353.     frames = 10;
  354.     widthX = 10;
  355.     widthY = 10;
  356.     checkerSize = 2;
  357.     height = 0.2;
  358.  
  359.     for (i = 1; i < argc; i++) {
  360.     if (strcmp(argv[i], "-ci") == 0) {
  361.         rgb = GL_FALSE;
  362.     } else if (strcmp(argv[i], "-rgb") == 0) {
  363.         rgb = GL_TRUE;
  364.     } else if (strcmp(argv[i], "-sb") == 0) {
  365.         doubleBuffer = GL_FALSE;
  366.     } else if (strcmp(argv[i], "-db") == 0) {
  367.         doubleBuffer = GL_TRUE;
  368.     } else if (strcmp(argv[i], "-dr") == 0) {
  369.         directRender = GL_TRUE;
  370.     } else if (strcmp(argv[i], "-ir") == 0) {
  371.         directRender = GL_FALSE;
  372.     } else if (strcmp(argv[i], "-grid") == 0) {
  373.         if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') {
  374.         printf("-grid (No numbers).\n");
  375.         return GL_FALSE;
  376.         } else {
  377.         widthX = atoi(argv[++i]);
  378.         widthY = atoi(argv[++i]);
  379.         }
  380.     } else if (strcmp(argv[i], "-size") == 0) {
  381.         if (i+1 >= argc || argv[i+1][0] == '-') {
  382.         printf("-checker (No number).\n");
  383.         return GL_FALSE;
  384.         } else {
  385.         checkerSize = atoi(argv[++i]);
  386.         }
  387.     } else if (strcmp(argv[i], "-wave") == 0) {
  388.         if (i+1 >= argc || argv[i+1][0] == '-') {
  389.         printf("-wave (No number).\n");
  390.         return GL_FALSE;
  391.         } else {
  392.         height = atof(argv[++i]);
  393.         }
  394.     } else if (strcmp(argv[i], "-frames") == 0) {
  395.         if (i+1 >= argc || argv[i+1][0] == '-') {
  396.         printf("-frames (No number).\n");
  397.         return GL_FALSE;
  398.         } else {
  399.         frames = atoi(argv[++i]);
  400.         }
  401.     } else {
  402.         printf("%s (Bad option).\n", argv[i]);
  403.         return GL_FALSE;
  404.     }
  405.     }
  406.     return GL_TRUE;
  407. }
  408.  
  409. int                     gl_width=300,gl_height=300;
  410.  
  411. const     ulong             APP_SIGNATURE = '????';
  412. const     ulong            MSG_REDRAW = 1;
  413.  
  414. class                     MesaWindow;
  415. class                     MesaView;
  416. class                    MesaApp;
  417.  
  418. // Lets make our life easy and make them global:
  419.  
  420. BBitmap                 *the_bitmap;
  421. MesaView                *the_view;    
  422. MesaWindow                 *the_window;
  423.  
  424. class MesaView : public BView
  425. {
  426.     public:
  427.     
  428.     MesaView(BRect frame):BView(frame,"Mesa View",B_FOLLOW_NONE,B_WILL_DRAW)
  429.     {
  430.     };
  431.     
  432.     void KeyDown(ulong aKey)
  433.     {
  434.         switch(aKey)
  435.         {
  436.             case    'c':
  437.             case    'C':
  438.                     contouring++;
  439.                     if (contouring == 1) 
  440.                     {
  441.                         static GLfloat map[4] = {0, 0, 20, 0};
  442.  
  443.                         glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE,
  444.                              GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1);
  445.                         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  446.                         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  447.                         glTexGenfv(GL_S, GL_OBJECT_PLANE, map);
  448.                         glTexGenfv(GL_T, GL_OBJECT_PLANE, map);
  449.                         glEnable(GL_TEXTURE_2D);
  450.                         glEnable(GL_TEXTURE_GEN_S);
  451.                         glEnable(GL_TEXTURE_GEN_T);
  452.                     }
  453.                     else if (contouring == 2) 
  454.                     {
  455.                         static GLfloat map[4] = {0, 0, 20, 0};
  456.  
  457.                         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  458.                         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  459.                         glPushMatrix();
  460.                         glMatrixMode(GL_MODELVIEW);
  461.                         glLoadIdentity();
  462.                         glTexGenfv(GL_S, GL_EYE_PLANE, map);
  463.                         glTexGenfv(GL_T, GL_EYE_PLANE, map);
  464.                         glPopMatrix();
  465.                     }
  466.                     else 
  467.                     {
  468.                         contouring = 0;
  469.                         glDisable(GL_TEXTURE_GEN_S);
  470.                         glDisable(GL_TEXTURE_GEN_T);
  471.                         glDisable(GL_TEXTURE_2D);
  472.                     }
  473.                     break;
  474.             case    's':
  475.             case    'S':            
  476.                     smooth = (GLenum)(!smooth);
  477.                     if (smooth) 
  478.                     {
  479.                         glShadeModel(GL_SMOOTH);
  480.                     } 
  481.                     else 
  482.                     {
  483.                         glShadeModel(GL_FLAT);
  484.                     }
  485.                     break;
  486.             case    'l':
  487.             case    'L':
  488.                     lighting = (GLenum)(!lighting);
  489.                     if (lighting) 
  490.                     {
  491.                         glEnable(GL_LIGHTING);
  492.                         glEnable(GL_LIGHT0);
  493.                         glEnable(GL_COLOR_MATERIAL);
  494.                     } 
  495.                     else 
  496.                     {
  497.                         glDisable(GL_LIGHTING);
  498.                         glDisable(GL_LIGHT0);
  499.                         glDisable(GL_COLOR_MATERIAL);
  500.                     }
  501.                     break;
  502.             case    'd':
  503.             case    'D':
  504.                     depth = (GLenum)(!depth);
  505.                     if (depth) 
  506.                     {
  507.                         glEnable(GL_DEPTH_TEST);
  508.                         clearMask = (GLenum)(clearMask|GL_DEPTH_BUFFER_BIT);
  509.                     } 
  510.                     else 
  511.                     {
  512.                         glDisable(GL_DEPTH_TEST);
  513.                         clearMask = (GLenum)(clearMask&(~GL_DEPTH_BUFFER_BIT));
  514.                     }
  515.                     break;
  516.             case    'a':
  517.             case    'A':
  518.                     spinMode = (GLenum)(!spinMode);
  519.                     break;
  520.         }
  521.     };
  522.     
  523.     void Draw(BRect frame)
  524.     {
  525.         DrawBitmap(the_bitmap,BPoint(0,0));
  526.     };                    
  527. };
  528.  
  529. class MesaWindow : public BWindow 
  530. {
  531.     public:
  532.     
  533.     MesaWindow(int width, int height):BWindow(BRect(0,0,width-1,height-1),"MesaView",B_TITLED_WINDOW,B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
  534.     {
  535.         // Move window to right position
  536.         MoveTo(80, 24);
  537.         // Create bitmap view
  538.         Lock();
  539.         AddChild(the_view = new MesaView(BRect(0, 0, (gl_width)-1, (gl_height)-1)));
  540.         the_view->MakeFocus();
  541.         Unlock();
  542.     };
  543.     
  544.     void MessageReceived(BMessage *msg)
  545.     {
  546.         switch(msg->what)
  547.         {    
  548.             case    MSG_REDRAW:
  549.                     Lock();
  550.                     the_view->DrawBitmap(the_bitmap,BPoint(0,0));
  551.                     Animate();
  552.                     Unlock();
  553.                     PostMessage(MSG_REDRAW);
  554.                     break;
  555.             default:
  556.                     BWindow::MessageReceived(msg);
  557.                     break;
  558.         }
  559.     };
  560.     
  561.     bool QuitRequested(void)
  562.     {
  563.         be_app->PostMessage(B_QUIT_REQUESTED);
  564.         return TRUE;
  565.     };
  566. };
  567.  
  568. class MesaApp : public BApplication 
  569. {
  570.     OSMesaContext ctx;
  571.     
  572.     public:
  573.     
  574.     MesaApp():BApplication(APP_SIGNATURE)
  575.     {
  576.         the_window = NULL;
  577.         the_bitmap = NULL;
  578.     };
  579.             
  580.     void ReadyToRun(void)
  581.     {
  582.         // Allocate the bitmap        
  583.         the_bitmap = new BBitmap(BRect(0, 0, gl_width-1, gl_height-1), B_RGB_32_BIT);
  584.  
  585.         uchar *bits = (uchar *)the_bitmap->Bits();
  586.  
  587.         memset(bits,0,the_bitmap->BytesPerRow()*gl_height);
  588.  
  589.         // Open window
  590.         the_window = new MesaWindow((gl_width),(gl_height));
  591.         the_window->Show();
  592.  
  593.         unsigned char *buffer;
  594.         double start,end;
  595.  
  596.         // Create an RGBA-mode context 
  597.         ctx = OSMesaCreateContext( GL_RGBA, NULL );
  598.  
  599.         // Bind the buffer to the context and make it current */
  600.         OSMesaMakeCurrent( ctx, bits, GL_UNSIGNED_BYTE, gl_width, gl_height );
  601.         OSMesaPixelStore( OSMESA_Y_UP, 0 );
  602.  
  603.         Init();
  604.         Reshape(gl_width,gl_height);
  605.         the_window->PostMessage(MSG_REDRAW);    
  606.     };
  607.  
  608.     bool QuitRequested(void)
  609.     {
  610.         // Make sure that the window closes first
  611.         if (BApplication::QuitRequested()) 
  612.         {
  613.             OSMesaDestroyContext( ctx );
  614.             if (the_bitmap)    delete the_bitmap;
  615.             return TRUE;
  616.         }
  617.         return FALSE;
  618.     };
  619.             
  620.     void AboutRequested(void)
  621.     {
  622.         char str[256];
  623.         sprintf(str, "MesaDemos, ported by Tinic Urou\n<5uro@informatik.uni-hamburg.de>\nFreely distributable.");
  624.         BAlert *the_alert = new BAlert("", str, "OK");
  625.         the_alert->Go();
  626.     };
  627. };
  628.  
  629. int main( int argc, char *argv[] )
  630. {
  631.     MesaApp *the_app;
  632.  
  633.     Args(argc,argv);
  634.  
  635.     the_app = new MesaApp();
  636.     the_app->Run();
  637.     delete the_app;
  638.  
  639.     return 0;
  640. }
  641.